<Project DefaultTargets="CreateTestEnvFile">
  <!-- This project creates a .cmd or .sh file that sets the environment variables corresponding to the specified Scenario property.
       For example, to create SetStressModes.cmd file for scenario "jitstress1" you can use the following command:

       dotnet msbuild testenvironment.proj /p:TestEnvFileName=SetStressModes.cmd /p:Scenario=jitstress1 /p:TargetsWindows=true
  -->


  <!-- DOTNET_* variables that can be specified for a test scenario -->
  <!-- There is a non-DOTNET variable here: RunningIlasmRoundTrip. When set to 1, this triggers CoreCLR round-trip testing.
       The value is read in the test wrapper scripts. When set in a __TestEnv script, it is set before it is read.
       The DOTNET_ processing handling below allows for variables not prefixed by 'DOTNET_'.
  -->
  <PropertyGroup>
    <DOTNETVariables>
      DOTNET_TieredCompilation;
      DOTNET_DbgEnableMiniDump;
      DOTNET_EnableCrashReport;
      DOTNET_DbgEnableElfDumpOnMacOS;
      DOTNET_DbgMiniDumpName;
      DOTNET_EnableAES;
      DOTNET_EnableAVX;
      DOTNET_EnableAVX2;
      DOTNET_EnableAVX512F;
      DOTNET_EnableBMI1;
      DOTNET_EnableBMI2;
      DOTNET_EnableFMA;
      DOTNET_EnableHWIntrinsic;
      DOTNET_EnableIncompleteISAClass;
      DOTNET_EnableLZCNT;
      DOTNET_EnablePCLMULQDQ;
      DOTNET_EnablePOPCNT;
      DOTNET_EnableSSE;
      DOTNET_EnableSSE2;
      DOTNET_EnableSSE3;
      DOTNET_EnableSSE3_4;
      DOTNET_EnableSSE41;
      DOTNET_EnableSSE42;
      DOTNET_EnableSSSE3;
      DOTNET_JitStressEvexEncoding;
      DOTNET_PreferredVectorBitWidth;
      DOTNET_MaxVectorTBitWidth;
      DOTNET_ForceRelocs;
      DOTNET_GCStress;
      DOTNET_GCName;
      DOTNET_gcServer;
      DOTNET_HeapVerify;
      DOTNET_JITMinOpts;
      DOTNET_JitELTHookEnabled;
      DOTNET_JitFakeProcedureSplitting;
      DOTNET_JitStress;
      DOTNET_JitStressProcedureSplitting;
      DOTNET_JitStressRegs;
      DOTNET_TailcallStress;
      DOTNET_ReadyToRun;
      DOTNET_TC_OnStackReplacement;
      DOTNET_TC_QuickJitForLoops;
      DOTNET_TC_OnStackReplacement_InitialCounter;
      DOTNET_TC_PartialCompilation;
      DOTNET_OSR_HitLimit;
      DOTNET_TieredPGO;
      DOTNET_JitEnableGuardedDevirtualization;
      DOTNET_EnableEHWriteThru;
      DOTNET_JitObjectStackAllocation;
      DOTNET_JitInlinePolicyProfile;
      DOTNET_JitClassProfiling;
      DOTNET_JitDelegateProfiling;
      DOTNET_JitVTableProfiling;
      DOTNET_JitEdgeProfiling;
      DOTNET_JitRandomGuardedDevirtualization;
      DOTNET_JitRandomEdgeCounts;
      DOTNET_JitRandomOnStackReplacement;
      DOTNET_JitRandomlyCollect64BitCounts;
      DOTNET_JitStressModeNames;
      DOTNET_JitGuardedDevirtualizationMaxTypeChecks;
      DOTNET_JitProfileCasts;
      DOTNET_TieredPGO_InstrumentedTierAlwaysOptimized;
      DOTNET_JitForceControlFlowGuard;
      DOTNET_JitCFGUseDispatcher;
      RunningIlasmRoundTrip;
      DOTNET_JitSynthesizeCounts;
      DOTNET_JitCheckSynthesizedCounts;
      DOTNET_JitRLCSEGreedy;
    </DOTNETVariables>
  </PropertyGroup>
  <ItemGroup>
    <DOTNETVariable Include="$(DOTNETVariables)" />
  </ItemGroup>

  <!-- Default values for some DOTNET_* variables -->
  <ItemDefinitionGroup>
    <TestEnvironment>
      <TieredCompilation>0</TieredCompilation>
      <DbgEnableMiniDump Condition="'$(TargetsWindows)' != 'true'">1</DbgEnableMiniDump> <!-- Enable minidumps for all scenarios -->
      <DbgMiniDumpName Condition="'$(TargetsWindows)' != 'true'">$HELIX_DUMP_FOLDER/coredump.%d.dmp</DbgMiniDumpName>
      <EnableCrashReport Condition="'$(TargetsWindows)' != 'true'">1</EnableCrashReport>
    </TestEnvironment>
  </ItemDefinitionGroup>

  <!-- TestEnvironment is a mapping between Scenario and DOTNET_* environment variable values that are written to __TestEnv file -->
  <ItemGroup>
    <!-- "normal" scenario doesn't define any DOTNET_* variables and uses the coreclr runtime default values
         while other scenarios use the default values of DOTNET_* variables defined in ItemDefinitionGroup above -->
    <TestEnvironment Include="normal" TieredCompilation="" />
    <TestEnvironment Include="jitminopts" JITMinOpts="1" />
    <TestEnvironment Include="no_tiered_compilation" TieredCompilation="0" />
    <TestEnvironment Include="forcerelocs" ForceRelocs="1" />
    <TestEnvironment Include="jitstress1" JitStress="1" />
    <TestEnvironment Include="jitstress2" JitStress="2" />
    <TestEnvironment Include="jitstress1_tiered" JitStress="1" TieredCompilation="1" />
    <TestEnvironment Include="jitstress2_tiered" JitStress="2" TieredCompilation="1" />
    <TestEnvironment Include="jitstress_isas_incompletehwintrinsic" EnableIncompleteISAClass="1"  />
    <TestEnvironment Include="jitstress_isas_nohwintrinsic" EnableHWIntrinsic="0" />
    <TestEnvironment Include="jitstress_isas_x86_evex" JitStressEvexEncoding="1" PreferredVectorBitWidth="512" />
    <TestEnvironment Include="jitstress_isas_x86_noaes" EnableAES="0" /> <!-- Depends on SSE2 -->
    <TestEnvironment Include="jitstress_isas_x86_noavx" EnableAVX="0" /> <!-- Depends on SSE42 -->
    <TestEnvironment Include="jitstress_isas_x86_noavx2" EnableAVX2="0" /> <!-- Depends on AVX -->
    <TestEnvironment Include="jitstress_isas_x86_noavx512" EnableAVX512F="0" /> <!-- Depends on AVX2 -->
    <TestEnvironment Include="jitstress_isas_x86_nobmi1" EnableBMI1="0" /> <!-- No dependencies -->
    <TestEnvironment Include="jitstress_isas_x86_nobmi2" EnableBMI2="0" /> <!-- No dependencies -->
    <TestEnvironment Include="jitstress_isas_x86_nofma" EnableFMA="0" /> <!-- Depends on AVX -->
    <TestEnvironment Include="jitstress_isas_x86_nohwintrinsic" EnableBMI1="0" EnableBMI2="0" EnableLZCNT="0" EnableSSE="0" />
    <TestEnvironment Include="jitstress_isas_x86_nolzcnt" EnableLZCNT="0" /> <!-- No dependencies -->
    <TestEnvironment Include="jitstress_isas_x86_nopclmulqdq" EnablePCLMULQDQ="0" /> <!-- Depends on SSE2 -->
    <TestEnvironment Include="jitstress_isas_x86_nopopcnt" EnablePOPCNT="0" /> <!-- Depends on SSE42 -->
    <TestEnvironment Include="jitstress_isas_x86_nosse" EnableSSE="0" /> <!-- No dependencies -->
    <TestEnvironment Include="jitstress_isas_x86_nosse2" EnableSSE2="0" /> <!-- Depends on SSE -->
    <TestEnvironment Include="jitstress_isas_x86_nosse3" EnableSSE3="0" /> <!-- Depends on SSE2 -->
    <TestEnvironment Include="jitstress_isas_x86_nosse3_4" EnableSSE3_4="0" /> <!-- Depends on SSE2 -->
    <TestEnvironment Include="jitstress_isas_x86_nosse41" EnableSSE41="0" /> <!-- Depends on SSSE3 and SSE3_4 -->
    <TestEnvironment Include="jitstress_isas_x86_nosse42" EnableSSE42="0" /> <!-- Depends on SSE41 -->
    <TestEnvironment Include="jitstress_isas_x86_nossse3" EnableSSSE3="0" /> <!-- Depends on SSE3 -->
    <TestEnvironment Include="jitstress_isas_x86_vectort128" JitStressEvexEncoding="1" MaxVectorTBitWidth="128" />
    <TestEnvironment Include="jitstress_isas_x86_vectort512" JitStressEvexEncoding="1" MaxVectorTBitWidth="512" />
    <TestEnvironment Include="jitstress_isas_1_x86_noaes" JitStress="1" EnableAES="0" /> <!-- Depends on SSE2 -->
    <TestEnvironment Include="jitstress_isas_1_x86_noavx" JitStress="1" EnableAVX="0" /> <!-- Depends on SSE42 -->
    <TestEnvironment Include="jitstress_isas_1_x86_noavx2" JitStress="1" EnableAVX2="0" /> <!-- Depends on AVX -->
    <TestEnvironment Include="jitstress_isas_1_x86_noavx512" JitStress="1" EnableAVX512F="0" /> <!-- Depends on AVX2 -->
    <TestEnvironment Include="jitstress_isas_1_x86_nobmi1" JitStress="1" EnableBMI1="0" /> <!-- No dependencies -->
    <TestEnvironment Include="jitstress_isas_1_x86_nobmi2" JitStress="1" EnableBMI2="0" /> <!-- No dependencies -->
    <TestEnvironment Include="jitstress_isas_1_x86_nofma" JitStress="1" EnableFMA="0" /> <!-- Depends on AVX -->
    <TestEnvironment Include="jitstress_isas_1_x86_nohwintrinsic" JitStress="1" EnableBMI1="0" EnableBMI2="0" EnableLZCNT="0" EnableSSE="0" />
    <TestEnvironment Include="jitstress_isas_1_x86_nolzcnt" JitStress="1" EnableLZCNT="0" /> <!-- No dependencies -->
    <TestEnvironment Include="jitstress_isas_1_x86_nopclmulqdq" JitStress="1" EnablePCLMULQDQ="0" /> <!-- Depends on SSE2 -->
    <TestEnvironment Include="jitstress_isas_1_x86_nopopcnt" JitStress="1" EnablePOPCNT="0" /> <!-- Depends on SSE42 -->
    <TestEnvironment Include="jitstress_isas_1_x86_nosse" JitStress="1" EnableSSE="0" /> <!-- No dependencies -->
    <TestEnvironment Include="jitstress_isas_1_x86_nosse2" JitStress="1" EnableSSE2="0" /> <!-- Depends on SSE -->
    <TestEnvironment Include="jitstress_isas_1_x86_nosse3" JitStress="1" EnableSSE3="0" /> <!-- Depends on SSE2 -->
    <TestEnvironment Include="jitstress_isas_1_x86_nosse3_4" JitStress="1" EnableSSE3_4="0" /> <!-- Depends on SSE2 -->
    <TestEnvironment Include="jitstress_isas_1_x86_nosse41" JitStress="1" EnableSSE41="0" /> <!-- Depends on SSSE3 and SSE3_4 -->
    <TestEnvironment Include="jitstress_isas_1_x86_nosse42" JitStress="1" EnableSSE42="0" /> <!-- Depends on SSE41 -->
    <TestEnvironment Include="jitstress_isas_1_x86_nossse3" JitStress="1" EnableSSSE3="0" /> <!-- Depends on SSE3 -->
    <TestEnvironment Include="jitstress_isas_2_x86_noaes" JitStress="2" EnableAES="0" /> <!-- Depends on SSE2 -->
    <TestEnvironment Include="jitstress_isas_2_x86_noavx" JitStress="2" EnableAVX="0" /> <!-- Depends on SSE42 -->
    <TestEnvironment Include="jitstress_isas_2_x86_noavx2" JitStress="2" EnableAVX2="0" /> <!-- Depends on AVX -->
    <TestEnvironment Include="jitstress_isas_2_x86_noavx512" JitStress="2" EnableAVX512F="0" /> <!-- Depends on AVX2 -->
    <TestEnvironment Include="jitstress_isas_2_x86_nobmi1" JitStress="2" EnableBMI1="0" /> <!-- No dependencies -->
    <TestEnvironment Include="jitstress_isas_2_x86_nobmi2" JitStress="2" EnableBMI2="0" /> <!-- No dependencies -->
    <TestEnvironment Include="jitstress_isas_2_x86_nofma" JitStress="2" EnableFMA="0" /> <!-- Depends on AVX -->
    <TestEnvironment Include="jitstress_isas_2_x86_nohwintrinsic" JitStress="2" EnableBMI1="0" EnableBMI2="0" EnableLZCNT="0" EnableSSE="0" />
    <TestEnvironment Include="jitstress_isas_2_x86_nolzcnt" JitStress="2" EnableLZCNT="0" /> <!-- No dependencies -->
    <TestEnvironment Include="jitstress_isas_2_x86_nopclmulqdq" JitStress="2" EnablePCLMULQDQ="0" /> <!-- Depends on SSE2 -->
    <TestEnvironment Include="jitstress_isas_2_x86_nopopcnt" JitStress="2" EnablePOPCNT="0" /> <!-- Depends on SSE42 -->
    <TestEnvironment Include="jitstress_isas_2_x86_nosse" JitStress="2" EnableSSE="0" /> <!-- No dependencies -->
    <TestEnvironment Include="jitstress_isas_2_x86_nosse2" JitStress="2" EnableSSE2="0" /> <!-- Depends on SSE -->
    <TestEnvironment Include="jitstress_isas_2_x86_nosse3" JitStress="2" EnableSSE3="0" /> <!-- Depends on SSE2 -->
    <TestEnvironment Include="jitstress_isas_2_x86_nosse3_4" JitStress="2" EnableSSE3_4="0" /> <!-- Depends on SSE2 -->
    <TestEnvironment Include="jitstress_isas_2_x86_nosse41" JitStress="2" EnableSSE41="0" /> <!-- Depends on SSSE3 and SSE3_4 -->
    <TestEnvironment Include="jitstress_isas_2_x86_nosse42" JitStress="2" EnableSSE42="0" /> <!-- Depends on SSE41 -->
    <TestEnvironment Include="jitstress_isas_2_x86_nossse3" JitStress="2" EnableSSSE3="0" /> <!-- Depends on SSE3 -->
    <TestEnvironment Include="jitstressregs1_x86_noavx" JitStressRegs="1" EnableAVX="0" />
    <TestEnvironment Include="jitstressregs2_x86_noavx" JitStressRegs="2" EnableAVX="0" />
    <TestEnvironment Include="jitstressregs3_x86_noavx" JitStressRegs="3" EnableAVX="0" />
    <TestEnvironment Include="jitstressregs4_x86_noavx" JitStressRegs="4" EnableAVX="0" />
    <TestEnvironment Include="jitstressregs8_x86_noavx" JitStressRegs="8" EnableAVX="0" />
    <TestEnvironment Include="jitstressregs0x10_x86_noavx" JitStressRegs="0x10" EnableAVX="0" />
    <TestEnvironment Include="jitstressregs0x80_x86_noavx" JitStressRegs="0x80" EnableAVX="0" />
    <TestEnvironment Include="jitstressregs0x1000_x86_noavx" JitStressRegs="0x1000" EnableAVX="0" />
    <TestEnvironment Include="jitstressregs0x2000_x86_noavx" JitStressRegs="0x2000" EnableAVX="0" />
    <TestEnvironment Include="jitstressregs1" JitStressRegs="1" />
    <TestEnvironment Include="jitstressregs2" JitStressRegs="2" />
    <TestEnvironment Include="jitstressregs3" JitStressRegs="3" />
    <TestEnvironment Include="jitstressregs4" JitStressRegs="4" />
    <TestEnvironment Include="jitstressregs8" JitStressRegs="8" />
    <TestEnvironment Include="jitstressregs0x10" JitStressRegs="0x10" />
    <TestEnvironment Include="jitstressregs0x80" JitStressRegs="0x80" />
    <TestEnvironment Include="jitstressregs0x1000" JitStressRegs="0x1000" />
    <TestEnvironment Include="jitstressregs0x2000" JitStressRegs="0x2000" />
    <TestEnvironment Include="jitstress2_jitstressregs1" JitStress="2" JitStressRegs="1" />
    <TestEnvironment Include="jitstress2_jitstressregs2" JitStress="2" JitStressRegs="2" />
    <TestEnvironment Include="jitstress2_jitstressregs3" JitStress="2" JitStressRegs="3" />
    <TestEnvironment Include="jitstress2_jitstressregs4" JitStress="2" JitStressRegs="4" />
    <TestEnvironment Include="jitstress2_jitstressregs8" JitStress="2" JitStressRegs="8" />
    <TestEnvironment Include="jitstress2_jitstressregs0x10" JitStress="2" JitStressRegs="0x10" />
    <TestEnvironment Include="jitstress2_jitstressregs0x80" JitStress="2" JitStressRegs="0x80" />
    <TestEnvironment Include="jitstress2_jitstressregs0x1000" JitStress="2" JitStressRegs="0x1000" />
    <TestEnvironment Include="jitstress2_jitstressregs0x2000" JitStress="2" JitStressRegs="0x2000" />
    <!-- There are multiple cases of `jitstress_random_*` so a single pipeline can run random JitStress multiple times without fear
         of a problem due to repeating the same scenario name. Note that this file is invoked with only one of these at a time.
    -->
    <TestEnvironment Include="jitstress_random_1" JitStress="random" />
    <TestEnvironment Include="jitstress_random_2" JitStress="random" />
    <TestEnvironment Include="jitelthookenabled" JitELTHookEnabled="1" />
    <TestEnvironment Include="jitelthookenabled_tiered" JitELTHookEnabled="1" TieredCompilation="1" />
    <TestEnvironment Include="tailcallstress" TailcallStress="1" />
    <TestEnvironment Include="gcstress0x3" GCStress="0x3" />
    <TestEnvironment Include="gcstress0xc" GCStress="0xC" />
    <TestEnvironment Include="gcstress0xf" GCStress="0xF" />
    <TestEnvironment Include="disabler2r" ReadyToRun="0" />
    <TestEnvironment Include="heapverify1" HeapVerify="1" />
    <TestEnvironment Include="gcstress0xc_disabler2r" GCStress="0xC" ReadyToRun="0" />
    <TestEnvironment Include="gcstress0xc_disabler2r_jitstress2" GCStress="0xC" ReadyToRun="0" JitStress="2" />
    <TestEnvironment Include="gcstress0xc_disabler2r_heapverify1" GCStress="0xC" ReadyToRun="0" HeapVerify="1" />
    <TestEnvironment Include="gcstress0xc_jitstress1" GCStress="0xC" JitStress="1" />
    <TestEnvironment Include="gcstress0xc_jitstress2" GCStress="0xC" JitStress="2" />
    <TestEnvironment Include="gcstress0xc_tailcallstress" GCStress="0xC" TailcallStress="1" />
    <TestEnvironment Include="gcstress0xc_jitminopts_heapverify1" GCStress="0xC" JITMinOpts="1" HeapVerify="1" />
    <TestEnvironment Include="jitosr_stress" TC_OnStackReplacement="1" TC_QuickJitForLoops="1" TC_OnStackReplacement_InitialCounter="1" OSR_HitLimit="1" TieredCompilation="1" />
    <TestEnvironment Include="jitosr_stress_random" TC_OnStackReplacement="1" TC_QuickJitForLoops="1" TC_OnStackReplacement_InitialCounter="1" OSR_HitLimit="2" TieredCompilation="1" JitRandomOnStackReplacement="15"/>
    <TestEnvironment Include="jit_stress_splitting" JitFakeProcedureSplitting="1" JitStressProcedureSplitting="1" />
    <TestEnvironment Include="jitpartialcompilation" TC_PartialCompilation="1" TC_QuickJitForLoops="1" TieredCompilation="1" />
    <TestEnvironment Include="jitpartialcompilation_pgo" TC_PartialCompilation="1" TC_QuickJitForLoops="1" TieredCompilation="1" TieredPGO="1" />
    <TestEnvironment Include="jitobjectstackallocation" JitObjectStackAllocation="1" TieredCompilation="0" />
    <TestEnvironment Include="jitphysicalpromotion_only" JitStressModeNames="STRESS_NO_OLD_PROMOTION" TieredCompilation="0" />
    <TestEnvironment Include="jitphysicalpromotion_full" JitStressModeNames="STRESS_PHYSICAL_PROMOTION_COST STRESS_NO_OLD_PROMOTION" TieredCompilation="0" />
    <TestEnvironment Include="jitcfg" JitForceControlFlowGuard="1" />
    <TestEnvironment Include="jitcfg_dispatcher_always" JitForceControlFlowGuard="1" JitCFGUseDispatcher="1" />
    <TestEnvironment Include="jitcfg_dispatcher_never" JitForceControlFlowGuard="1" JitCFGUseDispatcher="0" />
    <TestEnvironment Include="jitcfg_gcstress0xc" JitForceControlFlowGuard="1" GCStress="0xC" />
    <TestEnvironment Include="ilasmroundtrip" RunningIlasmRoundTrip="1" />
    <TestEnvironment Include="clrinterpreter" TieredCompilation="1" />
    <TestEnvironment Include="defaultpgo" TieredPGO="1" TieredCompilation="1" TC_QuickJitForLoops="1" />
    <TestEnvironment Include="fullpgo" TieredPGO="1" TieredCompilation="1" TC_QuickJitForLoops="1" ReadyToRun="0" JitProfileCasts="1"/>
    <TestEnvironment Include="fullpgo_methodprofiling" TieredPGO="1" TieredCompilation="1" TC_QuickJitForLoops="1" ReadyToRun="0" JitDelegateProfiling="1" JitVTableProfiling="1" />
    <TestEnvironment Include="fullpgo_methodprofiling_always_optimized" TieredPGO="1" TieredCompilation="1" TC_QuickJitForLoops="1" ReadyToRun="0" JitDelegateProfiling="1" JitVTableProfiling="1" TieredPGO_InstrumentedTierAlwaysOptimized="1" JitGuardedDevirtualizationMaxTypeChecks="3" JitProfileCasts="1" />
    <TestEnvironment Include="fullpgo_random_gdv" TieredPGO="1" TieredCompilation="1" TC_QuickJitForLoops="1" ReadyToRun="0" JitRandomGuardedDevirtualization="1" JitRandomlyCollect64BitCounts="1" />
    <TestEnvironment Include="fullpgo_random_gdv_methodprofiling_only" TieredPGO="1" TieredCompilation="1" TC_QuickJitForLoops="1" ReadyToRun="0" JitRandomGuardedDevirtualization="1" JitClassProfiling="0" JitDelegateProfiling="1" JitVTableProfiling="1" JitRandomlyCollect64BitCounts="1" />
    <TestEnvironment Include="fullpgo_random_gdv_edge" TieredPGO="1" TieredCompilation="1" TC_QuickJitForLoops="1" ReadyToRun="0" JitRandomGuardedDevirtualization="1" JitRandomEdgeCounts="1" JitRandomlyCollect64BitCounts="1" />
    <TestEnvironment Include="syntheticpgo" TieredCompilation="1" TC_QuickJitForLoops="1" ReadyToRun="0" JitSynthesizeCounts="1" JitCheckSynthesizedCounts="1" />
    <TestEnvironment Include="syntheticpgo_blend" TieredPGO="1" TieredCompilation="1" TC_QuickJitForLoops="1" ReadyToRun="0" JitSynthesizeCounts="3" JitCheckSynthesizedCounts="1" />
    <TestEnvironment Include="jitrlcse" JitRLCSEGreedy="1" />
    <TestEnvironment Include="gcstandalone" Condition="'$(TargetsWindows)' == 'true'" GCName="clrgc.dll"/>
    <TestEnvironment Include="gcstandalone" Condition="'$(TargetsWindows)' != 'true'" GCName="libclrgc.so"/>
    <TestEnvironment Include="gcstandaloneserver" Condition="'$(TargetsWindows)' == 'true'" gcServer="1" GCName="clrgc.dll"/>
    <TestEnvironment Include="gcstandaloneserver" Condition="'$(TargetsWindows)' != 'true'" gcServer="1" GCName="libclrgc.so"/>
  </ItemGroup>

  <!-- Create a random number for use by random JitStress. Note that we want to define a random value here,
       instead of letting the JIT create one, so the random number shows up in the log file for use reproducing
       any failures. The number doesn't need to be too random for the purpose of JitStress. We only create a single
       random number because we don't expect to need multiple different random numbers for different DOTNET
       variables. The number is hexadecimal because that's how CLR config values are interpreted.
       Using the milliseconds component of the current time is the current random number. That only gives us a
       range of 0-999. Probably better, if it matters, would be to use `Ticks` and "mod" it into an appropriate range.
  -->
  <PropertyGroup>
    <RandomNumber>$([System.DateTime]::Now.Millisecond.ToString("x"))</RandomNumber>
  </PropertyGroup>

  <!-- We use target batching on the DOTNETVariable items to iterate over the all DOTNET_* environment variables
       that can be specified by a test scenario. -->
  <Target Name="OutputDOTNETVariables" Inputs="@(DOTNETVariable)" Outputs="%(DOTNETVariable.Identity)">
    <PropertyGroup>
      <_DOTNETVariable>%(DOTNETVariable.Identity)</_DOTNETVariable>
      <_DOTNETVariableMetadataName>$(_DOTNETVariable.Replace('DOTNET_', ''))</_DOTNETVariableMetadataName>
    </PropertyGroup>

    <ItemGroup>
      <_TestEnvironment Include="@(TestEnvironment)" Condition="'%(Identity)' == '$(Scenario)'" />
      <_TestEnvironmentWithMetadata Include="@(_TestEnvironment->HasMetadata($(_DOTNETVariableMetadataName)))" />

      <!-- _TestEnvironmentWithMetadata can be either empty or contain one item:

       1) If _TestEnvironmentWithMetadata is empty, then this suggests that the test scenario with identity $(Scenario)
          doesn't define DOTNET_* environment variable with name $(_DOTNETVariable);

       2) Otherwise, the test scenario defines such DOTNET_* environment variable and the specified value
          of this variable can be extracted by using Metadata() item function.

       3) This is where we process a pseudo-value of "random" in the DOTNET table into an actual random number.
      -->

      <_DOTNETVariable Include="$(_DOTNETVariable)" Condition="@(_TestEnvironmentWithMetadata->Count()) == 1">
        <Value Condition="'@(_TestEnvironmentWithMetadata->Metadata($(_DOTNETVariableMetadataName)))' == 'random'">$(RandomNumber)</Value>
        <Value Condition="'@(_TestEnvironmentWithMetadata->Metadata($(_DOTNETVariableMetadataName)))' != 'random'">@(_TestEnvironmentWithMetadata->Metadata($(_DOTNETVariableMetadataName)))</Value>
      </_DOTNETVariable>
    </ItemGroup>

    <!-- Conceptually, this target creates a collection of _DOTNETVariable items that corresponds to
         DOTNET_* environment variables specified for the test scenario with identity $(Scenario) -->

  </Target>

  <Target Name="CreateTestEnvFile" DependsOnTargets="OutputDOTNETVariables">
    <ItemGroup Condition="'$(TargetsWindows)' == 'true'">
      <_TestEnvFileLine Include="@(_DOTNETVariable->'set %(Identity)=%(Value)')"  />

      <!-- Mono interpreter -->
      <_TestEnvFileLine Condition="'$(RuntimeVariant)' == 'monointerpreter'" Include="set MONO_ENV_OPTIONS=--interpreter" />

      <_TestEnvFileLine Condition="'$(RuntimeVariant)' != ''" Include="set DOTNET_RUNTIME_VARIANT=$(RuntimeVariant)" />

      <!-- CLR interpreter -->
      <_TestEnvFileLine Condition="'$(Scenario)' == 'clrinterpreter'" Include="set DOTNET_Interpret=%2A" /> <!-- %2A is asterisk / wildcard -->
      <_TestEnvFileLine Condition="'$(Scenario)' == 'clrinterpreter'" Include="set DOTNET_InterpreterHWIntrinsicsIsSupportedFalse=1" />
      <_TestEnvFileLine Condition="'$(Scenario)' == 'clrinterpreter'" Include="set DOTNET_InterpreterJITThreshold=0x1000" />
      <_TestEnvFileLine Condition="'$(Scenario)' == 'clrinterpreter'" Include="set DOTNET_TC_CallCountThreshold=0x1000" />
      <_TestEnvFileLine Condition="'$(Scenario)' == 'clrinterpreter'" Include="set DOTNET_InterpreterDoLoopMethods=1" />
    </ItemGroup>

    <ItemGroup Condition="'$(TargetsWindows)' != 'true'">
      <_TestEnvFileLine Include="#!/usr/bin/env bash" />
      <_TestEnvFileLine Include="@(_DOTNETVariable->'export %(Identity)=%(Value)')"  />

      <!-- Mono interpreter -->
      <_TestEnvFileLine Condition="'$(RuntimeVariant)' == 'monointerpreter'" Include="export MONO_ENV_OPTIONS=--interpreter" />

      <_TestEnvFileLine Condition="'$(RuntimeVariant)' != ''" Include="export DOTNET_RUNTIME_VARIANT=$(RuntimeVariant)" />

      <!-- Use Mono LLVM JIT when JIT-compiling the non-AOT-compiled parts of the runtime tests -->
      <!-- FIXME: temporarily disable LLVM JIT and use mini JIT until LLVM JIT support is brought back -->
      <_TestEnvFileLine Condition="'false' == 'true' and '$(RuntimeVariant)' == 'llvmaot'" Include="export MONO_ENV_OPTIONS=--llvm" />

      <!-- Use Mono in Full AOT mode when running the full-AOT-compiled runtime tests -->
      <_TestEnvFileLine Condition="'$(RuntimeVariant)' == 'llvmfullaot'" Include="export MONO_ENV_OPTIONS=--full-aot" />

      <_TestEnvFileLine Condition="'$(RuntimeVariant)' != ''" Include="export DOTNET_RUNTIME_VARIANT=$(RuntimeVariant)" />

      <!-- CLR interpreter -->
      <_TestEnvFileLine Condition="'$(Scenario)' == 'clrinterpreter'" Include="export DOTNET_Interpret=%2A" /> <!-- %2A is asterisk / wildcard -->
      <_TestEnvFileLine Condition="'$(Scenario)' == 'clrinterpreter'" Include="export DOTNET_InterpreterHWIntrinsicsIsSupportedFalse=1" />
      <_TestEnvFileLine Condition="'$(Scenario)' == 'clrinterpreter'" Include="export DOTNET_InterpreterJITThreshold=0x1000" />
      <_TestEnvFileLine Condition="'$(Scenario)' == 'clrinterpreter'" Include="export DOTNET_TC_CallCountThreshold=0x1000" />
      <_TestEnvFileLine Condition="'$(Scenario)' == 'clrinterpreter'" Include="export DOTNET_InterpreterDoLoopMethods=1" />
    </ItemGroup>

    <WriteLinesToFile File="$(TestEnvFileName)" Lines="@(_TestEnvFileLine)" Overwrite="true" />
  </Target>

</Project>
